package com.kgc.scd.service.impl;

import com.kgc.scd.entity.ShopGoods;
import com.kgc.scd.entity.ShopOrder;
import com.kgc.scd.entity.ShopUserBush;
import com.kgc.scd.mapper.BusyPurchaseMapper;
import com.kgc.scd.mapper.ShopOrderMapper;
import com.kgc.scd.mapper.ShopUserBushMapper;
import com.kgc.scd.service.BusyPurchaseService;
import com.kgc.scd.util.RedisUtils;
import com.kgc.scd.vo.ShopOrderVO;
import com.kgc.scd.vo.ShopUserBushVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created On : 2022/11/14.
 * <p>
 * Author : Administrator
 * <p>
 * Description: BusyPurchaseServiceImpl
 */

@Service
public class BusyPurchaseServiceImpl  implements BusyPurchaseService {

    @Autowired(required = false)
    private BusyPurchaseMapper busyPurchaseMapper;

    @Autowired(required = false)
    private ShopUserBushMapper shopUserBushMapper;

    @Autowired(required = false)
    private ShopOrderMapper shopOrderMapper;

    @Autowired
    private RedisUtils redisUtils;

    @Override
    public ShopGoods goodIsHot(String pid) {
        ShopGoods shopGoods=busyPurchaseMapper.selectById(pid);

        if(shopGoods!=null){
            if(shopGoods.isBush()){
                return shopGoods;
            }
        }
        return null;
    }

    @Override
    public boolean insertBushDetail(ShopUserBushVO shopUserBushVO) {

        ShopUserBush shopUserBush=new ShopUserBush();
        BeanUtils.copyProperties(shopUserBushVO,shopUserBush);
        if (shopUserBushMapper.insert(shopUserBush)>0){

            return true;
        }

        return false;
    }

    @Override
    public boolean insertShopOrderByEntity(ShopOrderVO shopOrderVO) {
        ShopOrder shopOrder=new ShopOrder();
        BeanUtils.copyProperties(shopOrderVO,shopOrder);
        if (shopOrderVO.getShoppingStatus().equals("未支付")){
            shopOrder.setShoppingStatus(1);
        }
        return shopOrderMapper.insert(shopOrder)>0;
    }
}
